const { add, get, xiu, cha,shan } = require("../api/distribution")
var express = require('express');
var router = express.Router();

//新增配送员
router.post('/addDistribution', async function (req, res, next) {
    const distribution = req.body;
    const data = await add(distribution);
    res.send(data);
});

router.get('/', async function (req, res, next) {
    const { curpage, eachPage } = req.query
    const data = await get({ curpage, eachPage })
    res.send(data);
});

router.patch('/updateDistribution', async function (req, res, next) {
    const { _id, phone, address } = req.body;
    const data = await xiu({ _id, phone, address });
    res.send(data);
});

router.post('/searchDistribution', async function (req, res, next) {
    const { name } = req.body
    const data = await cha({ name });
    res.send(data);
});

router.delete('/deleteDistribution', async function (req, res, next) {
    const { _id } = req.query
    const data = await shan({ _id });
    console.log(data);
    res.send(data);
});

module.exports = router;